import Vue from 'vue'
import App from './App.vue'
import router from './router'

import axios from 'axios'

import toast from './components/Toast'

import TreeTable from 'vue-table-with-tree-grid'

// 导入副文本编辑器
import VueQuillEditor from 'vue-quill-editor'
// require styles 导入对应的样式
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

// 导入nprogress包和css
import NProgress from 'nprogress'
import 'nprogress/nprogress'
 
Vue.use(VueQuillEditor, /* { default global options } */)

//使用插件
Vue.use(toast)

axios.defaults.baseURL = "http://127.0.0.1:8888/api/private/v1/"

//请求拦截器
axios.interceptors.request.use(config => {
  // 在请求拦截器中展示进度条
  NProgress.start()

  //为请求对象,添加Token验证的Authorization字段
  config.headers.Authorization = window.sessionStorage.getItem('token')
  return config
})
axios.interceptors.response.use(res => {
  // 在相应拦截器中隐藏进度条
  NProgress.done()
  return res
})

Vue.prototype.$http = axios

// 注册全局组件
Vue.component('tree-table', TreeTable)

// 定义全局过滤器
Vue.filter('dataFormat',function(originTime) {
  const dt = new Date(originTime)
  const y = dt.getFullYear();
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDate() + '').padStart(2, '0')

  const hh = (dt.getHours() + '').padStart(2, '0')
  const mm = (dt.getMinutes() + '').padStart(2, '0')
  const ss = (dt.getSeconds() + '').padStart(2, '0')
  
  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})

// 导入字体库
import './assets/fonts/iconfont.css'
import './assets/css/global.css'
Vue.config.productionTip = false



new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
